define(['WebPDF',
    'angularMocks',
    'app/js/Plugins/Form',
    './FormDataMock',
    '../../../app/js/Plugins/Form/models/FormPage',
    '../../../app/js/Plugins/Form/models/FormWidget',
    '../../../app/js/Plugins/Form/models/FormWidget_Combo',
    '../../../app/js/Plugins/Form/models/FormWidget_List',
    '../../../app/js/Plugins/Form/models/FormWidget_Radio',
    '../../../app/js/Plugins/Form/models/FormWidget_PushBtn',
    '../../../app/js/Plugins/Form/models/FormWidget_Text',
    '../../../app/js/Plugins/Form/models/FormWidget_Check'
  ],

  function(WebPDF, angularMocks, Form, FormData, FormPage, FormWidget,
    FormWidget_Combo, FormWidget_List, FormWidget_Radio,
    FormWidget_PushBtn, FormWidget_Text, Check) {
    'use strict';

    describe('FormDirective', function() {
      var $httpBackend;

      beforeEach(module('WebPDF', "FormPlugin"));

      beforeEach(inject(function(_$httpBackend_) {
        // $httpBackend = _$httpBackend_;
        // $httpBackend.expectGET('/auth.py');
        $httpBackend = _$httpBackend_;
        $httpBackend.whenGET('/app/pdfdata/doc-1/form_xmldata_3').respond(FormData[0]);
        $httpBackend.whenGET('/app/pdfdata/doc-1/form_xmldata_listbox1').respond(FormData.listbox1);
      }));

      it('create form-page', function(done) {
        inject(function($compile, $rootScope, $httpBackend) {
          var $scope = $rootScope.$new();
          $scope.pageIndex = 3;
          var element = $compile('<div form-page></div>')($scope);
          setTimeout(function() {
               done();
          }, 100);         
          $httpBackend.flush();
        });
      });

      it('create listbox', function(done) {
        inject(function($compile, $rootScope, $httpBackend, FormService) {
          FormService.getFormPage('listbox1').then(
            function(formPage) {
              var formWidget = formPage.getFormWidgetByName('List Box3');
              var newScope = $rootScope.$new();
              newScope.formWidget = formWidget;
              var template = "<div style='position: absolute' form-list-box />";
              var element = $compile(template)(newScope);
              
              setTimeout(function() {               
                expect(element.find('.option-wrapper').children().length).toBe(formWidget.options.length);
                 done();
               }, 100);                    
            }
          );
          $httpBackend.flush();
        });
      });
    });
  });